package com.lqd.mall.basis.response;

import com.lqd.mall.basis.code.CommonCode;
import com.lqd.mall.basis.code.CustomCode;
import com.lqd.mall.basis.code.ResultCode;
import com.lqd.mall.basis.constant.ResultMessageConstant;
import lombok.Getter;
import lombok.Setter;

/**
 * @author 零起点
 * @create 2022-01-11 17:14
 */
@Setter
@Getter
public class Result<T> extends CommonResult {

    private T data;

    public Result(ResultCode resultCode) {
        super(resultCode);
    }
    public Result() {
        super();
    }

    public Result(ResultCode resultCode, T t) {
        super(resultCode);
        data = t;
    }


    /**
     * 默认响应成功数据
     *
     * @return 响应数据
     */
    public static<T> Result<T> SUCCESS(T t) {
        return new Result<T>(CommonCode.SUCCESS, t);
    }

    /**
     * 自定义返回code
     *
     * @param code 响应code
     * @return 响应数据
     */
    public Result<T> SUCCESS(int code, T t) {
        return new Result<T>(new CustomCode(true, code, ResultMessageConstant.SUCCESSFUL_MESSAGE), t);
    }

    /**
     * 自定义返回提示信息
     *
     * @param message 提示信息
     * @return 响应数据
     */
    public    Result<T> SUCCESS(String message, T t) {
        return new Result<T>(new CustomCode(true, ResultMessageConstant.SUCCESSFUL_CODE, message), t);
    }


    public static<T> Result<T> FAIL(T t) {
        return new Result<T>(CommonCode.FAIL, t);
    }

    public Result<T> FAIL(int code, T t) {
        return new Result(new CustomCode(false, code, ResultMessageConstant.FAILURE_MESSAGE));
    }

    public static<T> Result<T> FAIL(String message, T t) {
        return new Result<T>(new CustomCode(false, ResultMessageConstant.FAILURE_CODE, message));
    }
}
